<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <meta content="no-cache" http-equiv="pragma"/>
    <meta content="no-cache" http-equiv="cache-control"/>
    <meta content="0" http-equiv="expires"/>
    <!-- 管局要求保持备案名称和网站使用名称一致 -->
    <title></title>
    <link rel="stylesheet" th:href="@{/y9static/css/default.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/y9static/y9-single-tenant/css/styles.css(v=1.0)}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/y9static/y9-single-tenant/css/demo.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/y9static/y9-single-tenant/css/loaders.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/y9static/css/layerMsg.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/y9static/js/verify-img/css/verify.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/y9static/js/layui/css/layui.css}" type="text/css"/>

    <script charset="utf-8" th:src="@{/y9static/js/jquery/jquery-3.7.1.min.js}" type="text/javascript"></script>
    <script charset="utf-8" th:src="@{/y9static/js/jquery/jquery.cookie.js}" type="text/javascript"></script>
    <script charset="utf-8" th:src="@{/y9static/js/base64.js}" type="text/javascript"></script>
    <script charset="utf-8" th:src="@{/y9static/js/jsencrypt.min.js(v=1.0)}" type="text/javascript"></script>
    <script charset="utf-8" th:src="@{/y9static/js/layui/layui.js}" type="text/javascript"></script>
    <script charset="utf-8" th:src="@{/y9static/js/layerMsg.js}" type="text/javascript"></script>
    <style>
        .logo {
            font-size: 20px;
            color: white;
        }

        #logo-name {
            padding-left: 10px;
        }

        body .logo img {
            width: auto;
            height: 50px;
        }
    </style>
</head>

<body>
<div class="logo"><img id="logo-img" th:src="@{/y9static/y9-single-tenant/img/cloud.png}"><span id="logo-name"></span></div>
<div class="login" id="tunnel">
    <div class="login_title">
        <span>用户登录</span>
    </div>
    <div class="login_fields">
        <form id="fm1" method="post" th:object="${credential}">
            <div class="login_fields__user">
                <div class="icon"><img alt="" th:src="@{/y9static/y9-single-tenant/img/username.png}"/></div>
                <input autocomplete="on" id="username" placeholder="用户名" tabindex="1" type="text" value=""/>
                <div class="validation"><img alt="" th:src="@{/y9static/y9-single-tenant/img/tick.png}"/></div>
            </div>
            <div class="login_fields__password">
                <div class="icon"><img alt="" th:src="@{/y9static/y9-single-tenant/img/password.png}"/></div>
                <input autocomplete="on" htmlescape="true" id="password" placeholder="请输入您的密码" tabindex="2"
                       type="password"/>
                <div class="validation"><img alt="" th:src="@{/y9static/y9-single-tenant/img/tick.png}"/></div>
            </div>
            <div class="alert alert-danger" th:if="${#fields.hasErrors('*')}">
                登录失败：<span th:each="err : ${#fields.errors('*')}" th:utext="${err}"/>
            </div>
            <!-- 表单隐藏数据块开始 -->
            <input id="username1" name="username" tabindex="1" type="hidden"/>
            <input id="password1" name="password" type="hidden"/>
            <input id="tenantShortName" name="tenantShortName" type="hidden"/>
            <input id="loginType" name="loginType" type="hidden" value="loginName"/>
            <input id="screenDimension" name="screenDimension" type="hidden" value=""/>
            <input id="rsaPublicKey" type="hidden" value=""/>
            <input name="execution" th:value="${flowExecutionKey}" type="hidden"/>
            <input name="_eventId" type="hidden" value="submit"/>
            <input name="geolocation" type="hidden"/>
            <!-- 表单隐藏数据块结束 -->
        </form>
        <!--点选验证码  -->
        <div id="mpanel6"></div>
        <div class="login_fields__submit">
            <input tabindex="3" type="button" value="登录"/>
        </div>
    </div>

</div>

<script charset="utf-8" th:src="@{/y9static/js/verify-img/verify.js(v=1.4)}" type="text/javascript"></script>
<script type="text/javascript">
    //var ctx = "[(${contextPath})]";
    var ctx = "/sso";

    $(function () {
        screenSize();
        initTenants();
    });

    function initTenants() {
        $.ajax({
            url: `${ctx}/api/singleTenant`,
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                $("#tenantShortName").val(data.shortName);
                if (data.logoIcon && data.logoIcon != null) {
                    // 获取图片元素
                    var image = document.getElementById('logo-img');
                    image.src = data.logoIcon;
                }
                if (data.description && data.description != null) {
                    document.getElementById('logo-name').innerHTML = data.description;
                }
                if (data.footer && data.footer != null) {
                    document.title = data.footer;
                }
            },
            error: function () {
                alert('获取数据失败');
            }
        });
    }

    function screenSize() {
        try {
            $("#screenDimension").val(window.screen.width + '*' + window.screen.height);
        } catch (e) {
        }
    }

    $(document).keydown(function (e) {
        // 回车键事件
        if (e.which === 13) {
            $('input[type="button"]').click();
        }
    });

    //加密
    function rsaEncrypt(publicKey, pwd) {
        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(publicKey);
        return encrypt.encryptOAEP(pwd);
    }

    var open = 0;
    layui.use("layer", function () {
        var option = {
            type: "success",
            position: "top-center",
            showicon: true,
            time: 3000,
            title: "登录提示",
            content: "提示",
            shadow: false,
            shadowclickclose: true,
            autoclose: true,
            callback: function (data, obj) {
                obj.ele.close(0);
            },
        };
        //非空验证
        $('input[type="button"]').click(function () {
            var username = $('#username').val();
            var password = $('#password').val();
            var tenantShortName = $("#tenantShortName").val();
            if (username == "") {
                option.type = "warn";
                option.content = "请输入您的账号";
                WfMsg(option);
            } else if (password == "") {
                option.type = "warn";
                option.content = "请输入密码";
                WfMsg(option);
            } else {
                $.when(
                        $.ajax({
                            async: false,
                            cache: false,
                            type: "GET",
                            url: ctx + '/api/getRsaPublicKey',
                            dataType: "json",
                            success: function (y9Result) {
                                if (y9Result.success) {
                                    $('#rsaPublicKey').val(y9Result.data);
                                }
                            }
                        })
                ).done(function () {
                    // 点选验证码
                    $("#mpanel6").pointsVerify({
                        imgSize: {
                            width: "288px",
                            height: "170px",
                        },
                        success: function () {
                            option.type = "success";
                            option.content = "登录中···";
                            WfMsg(option);

                            var username = $("#username").val();
                            var password = $("#password").val();
                            var rsaPublicKey = $("#rsaPublicKey").val();

                            //var encodeUsername = encode64(username);
                            //var encodePassword = encode64(password);
                            var encryptedUserName = rsaEncrypt(rsaPublicKey, username);
                            var encryptedPassword = rsaEncrypt(rsaPublicKey, password);
                            $("#username1").val(encryptedUserName);
                            $("#password1").val(encryptedPassword);
                            $("#fm1").submit();
                        },
                        error: function () {
                            option.type = "err";
                            option.content = "请按照顺序点击文字";
                            WfMsg(option);
                            // $(".verify-refresh").click();
                        },
                    });
                }).fail(function () {
                    option.type = "warn";
                    option.content = "获取随机数失败。";
                    WfMsg(option);
                });
            }
        });
    });
</script>
<script th:src="@{/y9static/y9-single-tenant/img/ThreeWebGL.js}" type="text/javascript"></script>
<script th:src="@{/y9static/y9-single-tenant/img/ThreeExtras.js}" type="text/javascript"></script>
<script th:src="@{/y9static/y9-single-tenant/img/Detector.js}" type="text/javascript"></script>
<script id="vs" type="x-shader/x-vertex">
    varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }
</script>
<script id="fs" type="x-shader/x-fragment">
    uniform sampler2D map; uniform vec3 fogColor; uniform float fogNear; uniform float fogFar; varying vec2 vUv; void main() { float depth = gl_FragCoord.z / gl_FragCoord.w; float fogFactor = smoothstep( fogNear, fogFar, depth ); gl_FragColor = texture2D( map, vUv ); gl_FragColor.w *= pow( gl_FragCoord.z, 20.0 ); gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor ); }
</script>
<script type="text/javascript">
    if (!Detector.webgl) Detector.addGetWebGLMessage();
    var canvas = document.createElement("canvas");
    canvas.width = 32;
    canvas.height = window.innerHeight;
    var context = canvas.getContext("2d");
    var gradient = context.createLinearGradient(0, 0, 0, canvas.height);
    gradient.addColorStop(0, "#1e4877");
    gradient.addColorStop(0.5, "#4584b4");
    context.fillStyle = gradient;
    context.fillRect(0, 0, canvas.width, canvas.height);
    document.body.style.background =
            "url(" + canvas.toDataURL("image/png") + ")";
    var container;
    var camera,
            scene,
            renderer,
            sky,
            mesh,
            geometry,
            material,
            i,
            h,
            color,
            colors = [],
            sprite,
            size,
            x,
            y,
            z;
    var mouseX = 0,
            mouseY = 0;
    var start_time = new Date().getTime();
    var windowHalfX = window.innerWidth / 2;
    var windowHalfY = window.innerHeight / 2;
    init();
    animate();

    function init() {
        container = document.createElement("div");
        document.body.appendChild(container);
        camera = new THREE.Camera(
                30,
                window.innerWidth / window.innerHeight,
                1,
                3000
        );
        camera.position.z = 6000;
        scene = new THREE.Scene();
        geometry = new THREE.Geometry();
        var texture = THREE.ImageUtils.loadTexture(
                ""
        );
        texture.magFilter = THREE.LinearMipMapLinearFilter;
        texture.minFilter = THREE.LinearMipMapLinearFilter;
        var fog = new THREE.Fog(0x4584b4, -100, 3000);
        material = new THREE.MeshShaderMaterial({
            uniforms: {
                map: {
                    type: "t",
                    value: 2,
                    texture: texture,
                },
                fogColor: {
                    type: "c",
                    value: fog.color,
                },
                fogNear: {
                    type: "f",
                    value: fog.near,
                },
                fogFar: {
                    type: "f",
                    value: fog.far,
                },
            },
            vertexShader: document.getElementById("vs").textContent,
            fragmentShader: document.getElementById("fs").textContent,
            depthTest: false,
        });
        var plane = new THREE.Mesh(new THREE.Plane(64, 64));
        for (i = 0; i < 8000; i++) {
            plane.position.x = Math.random() * 1000 - 500;
            plane.position.y = -Math.random() * Math.random() * 200 - 15;
            plane.position.z = i;
            plane.rotation.z = Math.random() * Math.PI;
            plane.scale.x = plane.scale.y =
                    Math.random() * Math.random() * 1.5 + 0.5;
            GeometryUtils.merge(geometry, plane);
        }
        mesh = new THREE.Mesh(geometry, material);
        scene.addObject(mesh);
        mesh = new THREE.Mesh(geometry, material);
        mesh.position.z = -8000;
        scene.addObject(mesh);
        renderer = new THREE.WebGLRenderer({
            antialias: false,
        });
        renderer.setSize(window.innerWidth, window.innerHeight);
        container.appendChild(renderer.domElement);
        document.addEventListener("mousemove", onDocumentMouseMove, false);
        window.addEventListener("resize", onWindowResize, false);
    }

    function onDocumentMouseMove(event) {
        mouseX = (event.clientX - windowHalfX) * 0.25;
        mouseY = (event.clientY - windowHalfY) * 0.15;
    }

    function onWindowResize(event) {
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
        renderer.setSize(window.innerWidth, window.innerHeight);
    }

    function animate() {
        requestAnimationFrame(animate);
        render();
    }

    function render() {
        position = ((new Date().getTime() - start_time) * 0.03) % 8000;
        camera.position.x += (mouseX - camera.target.position.x) * 0.01;
        camera.position.y += (-mouseY - camera.target.position.y) * 0.01;
        camera.position.z = -position + 8000;
        camera.target.position.x = camera.position.x;
        camera.target.position.y = camera.position.y;
        camera.target.position.z = camera.position.z - 1000;
        renderer.render(scene, camera);
    }
</script>

</body>
</html>